package org.pr.ddddesigner.infrastructure.r2dbc;

import jakarta.annotation.Nonnull;
import org.pr.ddddesigner.infrastructure.po.CreateUpdateTime;
import org.reactivestreams.Publisher;
import org.springframework.data.r2dbc.mapping.event.BeforeConvertCallback;
import org.springframework.data.relational.core.sql.SqlIdentifier;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Mono;

import java.time.Instant;

/**
 * @author chenbin
 */
@Component
public class EntityUpdateTimeCallback implements BeforeConvertCallback<CreateUpdateTime> {
    @Nonnull
    @Override
    public Publisher<CreateUpdateTime> onBeforeConvert(@Nonnull CreateUpdateTime entity, @Nonnull SqlIdentifier table) {
        entity.setUpdateTime(Instant.now());
        return Mono.just(entity);
    }
}
